/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package back;

import Definitions.ManagerException;
import businessLogic.CreateUserBeanLocal;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

/**
 *
 * @author Jirka
 */
public class CreateUserBack {

    @EJB
    private CreateUserBeanLocal createUserBean;
    private String login = "";
    private String password = "";
    private String password2 = "";

    public String getLogin() {
        return login;
    }

    public String getPassword() {
        return password;
    }

    public String getPassword2() {
        return password2;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setPassword2(String password2) {
        this.password2 = password2;
    }

    public String register() {
        return "registration";
    }

    public String createManager() {
        if (!password.equals(password2)) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Hesla se neshodují"));
            return "login";
        }
        try {
            createUserBean.createUser(login, password);
        } catch (ManagerException ex) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(ex.getMessage()));
            return "login";
        }
        return "login";
    }
}
